
var api = require('../../utils/api.js');
var app = getApp();


Page({
  data: {
    id:'',
    services: [],
    hospital:''
  },

    onLoad(ret){
        console.log(ret);
        this.setData({
            id:ret.id
        })
        this.gethospitalbyid();
        this.gethospitalserver();

        var add=wx.getStorageSync('address');

        if (!add){
            wx.showToast({
                title: '请选择地区',
                icon:'none'
            })
          wx.navigateTo({
            url: '/pages/index/address',
          })
        }


    },

    openmap(){

          var hospital=this.data.hospital;
          wx.openLocation({
            latitude: parseFloat(hospital.lat), // 纬度
            longitude: parseFloat(hospital.lng), // 经度
            name: 'name', // 位置名称
            scale: 28, // 缩放比例
            success: function () {
              console.log('地图打开成功');
            },
            fail: function (err) {
              console.error('地图打开失败', err);
            }
          });


      
   
    },

    // 医院详情
    gethospitalbyid(){
        var that=this;
        var id=this.data.id;
        api.post({
            url: 'hospital/gethospitalbyid',
            data: {id:id},
            success: data => {
                console.log(data)
                that.setData({
                    hospital:data.data
                })
            }
        })
    },
    //服务信息
    gethospitalserver(){
        var that=this;
        var id=this.data.id;
        api.post({
            url: 'hospital/gethospitalserver',
            data: {id:id},
            success: data => {
                console.log(data)
                that.setData({
                    server:data.data
                })
            }
        })
    },


    goapply: function (e) {
        const serviceId = e.currentTarget.dataset.sid;
        const id=this.data.id;

        wx.navigateTo({
        url: '/pages/index/apply?id='+id+'&sid='+serviceId,
        })

        // 这里可以添加实际的预约逻辑
    },
  seesinfo(e){
    const serviceId = e.currentTarget.dataset.sid;
    wx.navigateTo({
        url: '/pages/comment/info?id='+serviceId,
    })

  }

})
